import { createRouter, createWebHashHistory } from 'vue-router'
import login from '../views/login.vue';
import menu from '../views/menu.vue';
import userManagement from '../views/user/userManagement.vue';
import pageError from '../views/pageError.vue';
import RegistCustomer from '../views/customer/RegistCustomer.vue';
import OutwardCustomer from '../views/customer/OutwardCustomer.vue';
import ExitCustomer from '../views/customer/ExitCustomer.vue';
import BedManagement from '../views/Bed/BedManagement.vue';
import BedView from '../views/Bed/BedView.vue';
import DietConfig from '../views/customer/DietConfig.vue';
import DietCalendar from '../views/customer/DietCalendar.vue';
import CareLevelList from '../views/Care/CareLevelList.vue';
import CareProjectList from '../views/Care/CareProjectList.vue';
import LevelProjectList from '../views/Care/LevelProjectList.vue';
import LevelProjectAdd from '../views/Care/LevelProjectAdd.vue';
import CustomerCareConfig from '../views/Care/CustomerCareConfig.vue';
import ConfigDetail from '../views/Care/ConfigDetail.vue';
import CustomerCareRecord from '../views/Care/CustomerCareRecord.vue';
import RecordDetail from '../views/Care/RecordDetail.vue';
import HealthManagerList from '../views/HealthManager/HealthManagerList.vue';
import SetServiceObject from '../views/HealthManager/SetServiceObject.vue';
import menu1 from '../views/menu1.vue';
import CareRecord from '../views/HealthManager/CareRecord.vue';
import RecordDetail2 from '../views/HealthManager/RecordDetail2.vue';
import CustomerList from '../views/HealthManager/CustomerList.vue';
import ServiceAttention from '../views/HealthManager/ServiceAttention.vue';
import BuyCareProject from '../views/HealthManager/BuyCareProject.vue';
import OutboundApplication from '../views/OutboundApplication/OutboundApplication.vue';
import DailyCare from '../views/DailyCare/DailyCare.vue';
import CheckOutRegistration from '../views/NurseUserManagement/CheckOutRegistration.vue';
import CheckOutRecord from '../views/NurseUserManagement/CheckOutRecord.vue';
import OutboundCustomerList from '../views/OutboundApplication/OutboundCustomerList.vue';
import AI from '../views/AI/AI.vue';
import AI1 from '../views/AI/AI1.vue';


const routes = [
  {
      path: '/',
      redirect: '/login'
  },
  {
    path: '/login',
    component: login
  },
  {
      path: '/menu',
      component: menu,
      children: [
        {
          path: '/userManagement',
          component: userManagement
        },
		{
			path: '/RegistCustomer',
			component: RegistCustomer
		},
		{
			path: '/OutwardCustomer',
			component: OutwardCustomer
		},
		{
			path: '/ExitCustomer',
			component: ExitCustomer
		},
		{
			path: '/BedManagement',
			component: BedManagement
		},
		{
			path: '/BedView',
			component: BedView
		},
		{
			path: '/DietConfig',
			component: DietConfig
		},
		{
			path: '/DietCalendar',
			component: DietCalendar
		},
		{
			path: '/CareLevelList',
			component: CareLevelList
		},
		{
			path: '/CareProjectList',
			component: CareProjectList
		},
		{
			path: '/LevelProjectList',
			component: LevelProjectList
		},
		{
			path: '/LevelProjectAdd',
			component: LevelProjectAdd
		},
		{
			path: '/CustomerCareConfig',
			component: CustomerCareConfig
		},
		{
			path: '/ConfigDetail',
			component: ConfigDetail
		},
		{
			path: '/CustomerCareRecord',
			component: CustomerCareRecord
		},
		{
			path: '/RecordDetail',
			component: RecordDetail
		},
		{
			path: '/HealthManagerList',
			component: HealthManagerList
		},
		{
			path: '/SetServiceObject',
			component: SetServiceObject
		},
		{
			path: '/CustomerList',
			component: CustomerList
		},
		{
			path: '/ServiceAttention',
			component: ServiceAttention
		},
		{
			path: '/BuyCareProject',
			component: BuyCareProject
		},
		{
			path: '/AI',
			component: AI
		}	
      ]
    },
	{
		path: '/menu1',
		component: menu1,
		children: [
			{
				path: '/DailyCare',
				component:DailyCare
			},
			{
				path: '/CareRecord',
				component: CareRecord
			},
			{
				path: '/RecordDetail2',
				component: RecordDetail2
			},
			{
				path: '/OutboundApplication',
				component:OutboundApplication
			},
			{
				path: '/CheckOutRegistration',
				component: CheckOutRegistration
			},
			{
				path: '/CheckOutRecord',
				component: CheckOutRecord
			},
			{
				path: '/OutboundCustomerList',
				component: OutboundCustomerList
			},
			{
				path: '/AI1',
				component: AI1
			}	
		]
	},
	{
		path: '/pageError',
		component: pageError
	}
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 添加全局路由守卫
router.beforeEach((to, from, next) => {
    //创建守卫规则集合(这里表示数组中的路径使用前需要权限验证)
    const nextRoute = ['/login', '/pageError'];
    // 从session来获取登录者的状态
    let result=sessionStorage.getItem('token');
    // 判断to.path(要跳转的路径)是否是需要权限验证的
    if (nextRoute.indexOf(to.path)==-1) {
        if (result==null||result==undefined) {
            router.push({
                path: '/login'
            })
            //location.reload(); 
        }
    }
    next(); //必须要有
});
  
  
export default router
